src=bootloader.S
out=./out
obj=$(out)/bootloader.o
elf=$(out)/bootloader.elf
boot=$(out)/bootloader.out
asm=$(out)/bootloader.asm
kernel=$(out)/kernel/kernel.out


all:
	mkdir -p $(out)
	gcc -c $(src) -m32 -o $(obj) # -m32, 编译32位的文件
	ld -m elf_i386 $(obj) -e start -Ttext 0x7c00 -o $(elf) # 连接,如果需要编译x86_64,可修改位elf_x86_64
	objcopy -S -O binary -j .text $(elf)  $(boot) #
	objdump -S $(elf) > $(asm)
	@dd if=/dev/zero of=$(boot) seek=2 count=2878 >> /dev/zero

fat12:all
	@ls -al $(boot)
	cd kernel;make address=0xc400;
	sudo mount -o loop $(boot) /mnt
	sudo cp $(kernel) /mnt
	-ls -al /mnt
	sudo umount /mnt

run:fat12
	qemu-system-i386 -drive file=$(boot)

clean:
	-rm -rf $(out)/*
